import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

/**
 * class for insert the server ip by the user
 */
public class EnterIP extends JFrame  {

	
	final public static int DEFAULT_PORT = 5555;
	
	private JPanel enterPanel;
	/**
	 * label for enter ip 
	 */
	private JLabel lblEnterIP;
	private String IP = "localhost";
	private JTextField IPText;
	
	/**
	 * @wbp.parser.constructor
	 */
	public EnterIP (){
		initialize();
	}
	
	
	private void initialize() {
		
		this.setSize(342, 187);
		this.setLocation(430, 200);
		enterPanel = new JPanel();
		getContentPane().add(enterPanel);
		enterPanel.setLayout(null);
		
		lblEnterIP = new JLabel("Enter Server IP");
		lblEnterIP.setBounds(120, 11, 89, 14);
		enterPanel.add(lblEnterIP);
		
		
	
	
		
		IPText = new JTextField();
		IPText.setBounds(87, 61, 162, 20);
		IPText.addFocusListener(new java.awt.event.FocusAdapter() 
		{
			public void focusLost(java.awt.event.FocusEvent e) 
			{
				System.out.println("focusLost()"); 
				IP=IPText.getText();			
			}
		}
		);
		enterPanel.add(IPText);
		IPText.setColumns(10);
		
		enterPanel.add(getOK());

		this.setTitle("Academic Managment Tool");
		this.setVisible(true);
	}	
	
	
	private JButton getOK()
	{
		JButton btnOKButton = new JButton("OK");
		btnOKButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				setVisible(false);
				
				Global.chat= new ClientConsole(IP, DEFAULT_PORT);
			    SQL s = new SQL(null,22);
			    s.accept();
			    Global.sem=(String)s.getMsg();
			    System.out.println("this sem is "+ Global.sem);
			    System.out.println("this ip is "+ IP);
			    Global.main = new MainScreen();

			}
		});
		btnOKButton.setBounds(120, 115, 89, 23);
		return btnOKButton;
	}


	/**
	 * @return the iP
	 */
	public String getIP() {
		return IP;
	}


	/**
	 * @param iP the iP to set
	 */
	public void setIP(String iP) {
		IP = iP;
	}
}